<?php
include(_DOC_ROOT.'classes/Content/Content.php');
include(_DOC_ROOT.'classes/Customer/Customer.php');
include_once(_DOC_ROOT.'lib/mail/class.phpmailer.php');
$module = ($module)?$module:'forgot-password';
if(isset($module)) {
	$pobj = new Content();
	$page = $pobj->getContent($module);
	$page['images'] = getEntityImages($module);
	$_META_TITLE = $page['meta_title'];
	$_META_KEYWORD = $page['meta_keyword'];
	$_META_DESCRIPTION = $page['meta_description'];
	
	$customer = new Customer();
	if(isset($_POST['forgot_password'])) {
	$lobj = new login();
		if($customer_arr = $lobj->get_password($_POST['user_name'])) {
		
		$errmsg = 'Check your email account, your password has been sent.';
		try {
				$mail = new PHPMailer();
				$name = $customer_arr['first_name'].' '.$customer_arr['last_name'];
				$email = $customer_arr['email'];
				$link = _SITE_URL.'register';
				$password = $customer_arr['password'];
				$mail = new PHPMailer();
				$mail->From       = "admin@dialshaadi.com";
				$mail->FromName   = "Dialshaadi";
				$mail->AddAddress("$email", "$name");
				$mail->Subject    = "Dialshaadi password retrival.";
				$body = file_get_contents('template/email/forgot-password.tpl');
				$body = eregi_replace("[\]",'',$body);
				$find = array('#USERNAME#','#PASSWORD#','#NAME#','#HOST_NAME#');
				$replace = array($email,$password,$name,$link);
				$body = str_replace($find,$replace,$body);
				$mail->MsgHTML($body);
				if(!$mail->Send()) 
				{
					//die("Mailer Error: " . $mail->ErrorInfo);
				}
			}
			catch(Exception  $e){
			}
		}
		else
			$errmsg = 'Invalid email address.';
	}
	
}

	$_tplName = 'forgot-password.tpl';
	$brd_url['SignIn'] = _SITE_URL.'register';
	//print_r($brd_url);

$footer_links_tpl = 'footer_main_links.tpl';
include(_SITE_TPL_PATH_.'site_main.tpl');
?>